﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Data.SqlClient;
using HotelManager.DataAccess;
using HotelManager.Model;
using HotelManager.Core;

namespace HotelManager.View
{
    public partial class FormThuePhong : Form
    {
        ThuePhongAccess thuePhongAccess = new ThuePhongAccess();
        DataTable dsthuephong = new DataTable();
        public FormThuePhong()
        {
            InitializeComponent();
        }

        private void txtNhanvien_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void FormThuePhong_Load(object sender, EventArgs e)
        {
            dsthuephong = thuePhongAccess.laytoanbophongthue();
            dataGridView1.DataSource = dsthuephong;
        }

        private void txtSdt_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormDetailKhachhang frmCTkh = new FormDetailKhachhang();
            frmCTkh.Show();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtMaso.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            txtMaphong.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            dtMuon.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            dtTra.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            txtMakhach.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            txtSoluong.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
            txtTiendatcoc.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
            txtTongtra.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString();
            txtManhanvien.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            ThuePhong thuephong = new ThuePhong(txtMaso.Text, txtMaphong.Text, DateTime.Parse(dtMuon.Text), DateTime.Parse(dtTra.Text), txtMakhach.Text, int.Parse(txtSoluong.Text), int.Parse(txtTiendatcoc.Text), int.Parse(txtTongtra.Text), txtManhanvien.Text);

            if (thuePhongAccess.themThuePhong(thuephong) == 0)
            {
                MessageBox.Show("Mã đồ dùng đã tồn tại!");
            }
            else
            {
                MessageBox.Show("Thêm thành công!");
            }
            FormThuePhong_Load(sender, e);
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            ThuePhong thuephong = new ThuePhong(txtMaso.Text, txtMaphong.Text, DateTime.Parse(dtMuon.Text), DateTime.Parse(dtTra.Text), txtMakhach.Text, int.Parse(txtSoluong.Text), int.Parse(txtTiendatcoc.Text), int.Parse(txtTongtra.Text), txtManhanvien.Text);

            if (thuePhongAccess.suaThuePhong(thuephong) == 0)
            {
                MessageBox.Show("Mã đồ dùng đã tồn tại!");
            }
            else
            {
                MessageBox.Show("Sửa thành công!");
            }
            FormThuePhong_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            ThuePhong thuephong = new ThuePhong(txtMaso.Text, txtMaphong.Text, DateTime.Parse(dtMuon.Text), DateTime.Parse(dtTra.Text), txtMakhach.Text, int.Parse(txtSoluong.Text), int.Parse(txtTiendatcoc.Text), int.Parse(txtTongtra.Text), txtManhanvien.Text);

            if (thuePhongAccess.xoaThuePhong(thuephong) == 0)
            {
                MessageBox.Show("Mã đồ dùng không tồn tại!");
            }
            else
            {
                MessageBox.Show("Xóa thành công! ");
            }
            FormThuePhong_Load(sender, e);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                txtMaso.ReadOnly = false;
                btnThem.Enabled = true;
            }
            else
            {
                txtMaso.ReadOnly = true;
                btnThem.Enabled = false;
            }
        }

        private void txtMaso_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
